﻿using System.Windows.Forms;
using FluentParser.Expressions;

namespace FluentParser.Editor
{
    public class Colorizer
    {
        private readonly RichTextBox _rtb;

        public Colorizer(RichTextBox rtb)
        {
            _rtb = rtb;
        }

        public void Apply(ParsingNodeResult node)
        {
            if (node.IsSuccess)
            {
                if (node.Expression.Color.HasValue)
                {
                    _rtb.Select(node.Index, node.Length);
                    _rtb.SelectionColor = node.Expression.Color.Value;
                }

                foreach (ParsingNodeResult child in node.Nodes)
                {
                    Apply(child);
                }
            }
        }
    }
}
